// JavaScript Document
function list_pt() {
	req_ajax_get('/icp/index.php/admin/pt/listpt', list_pt_success);
}

function list_pt_success(result, status){
	$("#content_box").html(result);
}

function update_pt(id) {
	var postData="ptid="+id;
	req_ajax(postData, '/icp/index.php/admin/pt/update', update_pt_success);
}

function update_pt_success(result, status) {
	$("#container_detail_obj").html("");
    $("#container_detail_obj").html(result);
    $("#detail_pt").modal({keyboard: true, backdrop:'static'});
}

function do_update_pt(id) {
	var pt_name = $.trim($('#pt_name').val());
	if (pt_name == "") {
		alert('请输入平台名');
		$('#pt_name').focus();
		return false;
	}
	
	var pt_addr = $.trim($('#pt_addr').val());
	if (pt_addr == "") {
		alert("请输入平台地址");
		$('#pt_addr').focus();
		return false;
	}
	
	var pt_url = $.trim($('#pt_url').val());
	if (pt_url == "") {
		alert("请输入平URL");
		$('#pt_url').focus();
		return false;
	}
	var pt_level = $.trim($('#pt_level').val());
	if (pt_level == "") {
		alert("请输入风险等级");
		$('#pt_level').focus();
		return false;
	}
	var pt_status = $.trim($('#pt_status').val());
	if (pt_status == "") {
		alert("请选择初始状态");
		$('#pt_status').focus();
		return false;
	}

	var postData="pt_id="+id+"&pt_name="+pt_name+"&pt_addr="+pt_addr+"&pt_url="+pt_url+"&pt_level="+pt_level+"&pt_status="+pt_status;
	alert(postData);
	req_ajax(postData, '/icp/index.php/admin/pt/do_update', do_update_pt_success);
}

function do_update_pt_success(result, status) {
	jsonData = eval(result);//生成json对象
	alert(jsonData.content);
	if (jsonData.status == 1) {
		hideModal("detail_pt");
		list_pt();
	}
}

function del_pt(id) {
	if (id > 0) {
		var name = $.trim($("#name_ckb_pt_"+id).html());
		var r = confirm("确定要删除:"+name+"?"); 
		if (r == true) {
			var postData = "ptid="+id;
			req_ajax(postData, '/icp/index.php/admin/pt/del', del_pt_success);
		}
	}
}

function del_pt_success(result, status) {
	jsonData = eval(result);//生成json对象
	alert(jsonData.content);
	if (jsonData.status == 1) {
		list_pt();
	}
}

function del_pts() {
	var sel_obj = get_select_ids("ckb_pt");
    if(sel_obj.ids.length <= 0){
        alert("请选择要删除的平台");
    	return;
   	}
	var r = confirm("确定要删除:"+sel_obj.names+"?"); 
    if (r == true){
    	var postData = "ptid="+sel_obj.ids;
        req_ajax(postData, "/icp/index.php/admin/pt/del", del_pt_success);
    }
}

function edit_pt(id) {
	var postData="ptid="+id;
	req_ajax(postData, '/icp/index.php/admin/pt/update', update_pt_success);
}